import { useRouter } from 'next/router'

export default function Post ({data}) {
  const router = useRouter()
  if (router.isFallBack) return <div>loading</div>
  return <div>
    <span>{data.id}</span>
    <span>{data.title}</span>
  </div>
}

// 返回路由参数
export async function getStaticPaths () {
  return {
    paths: [{params: {id: '1'}}, {params: {id: '2'}}],
    fallback: true // fasle 404
  }
}

// 返回路由参数对应的数据
export async function getStaticProps ({params}) {
  const id = params.id
  let data
  switch(id) {
    case '1':
      data = {id: '1', title: 'title1'}
      break
    case '2':
      data = {id: '2', title: 'title2'}
      break
    case '3':
      data = {id: '3', title: 'title3'}
      break
    default:
      data = null
      break
  }
  return {
    props: {
      data
    }
  }
}